<template>
  <dl>
    <dd>
      <div>
        <span class="tit">发布时间：</span>
        <el-select v-model="form.issue_date" placeholder="请选择">
          <el-option
            v-for="item in option.issue_date"
            :key="item.key"
            :label="item.label"
            :value="item.key">
          </el-option>
        </el-select>
      </div>
      <div>
        <span class="tit">状态：</span>
        <el-select v-model="form.status" placeholder="请选择">
          <el-option
            v-for="item in option.status"
            :key="item.key"
            :label="item.label"
            :value="item.key">
          </el-option>
        </el-select>
      </div>
    </dd>
    <dd>
      <span class="tit">类型：</span>
      <p class="cont">
        <span v-for="(item, index) in option.type" :key="index" :class="{active: form.type === item.key}" @click="handleChangeItem('type', item)">{{item.key}}</span>
      </p>
    </dd>
    <dd>
      <span class="tit">标准性质：</span>
      <p class="cont">
        <span v-for="(item, index) in option.std_nature" :key="index" :class="{active: form.std_nature === item.key}" @click="handleChangeItem('std_nature', item)">{{item.key}}</span>
      </p>
    </dd>
  </dl>
</template>

<script>
export default {
  data() {
    return {
      form: {
        issue_date: '全部', // 发布时间
        status: '全部', // 状态
        type: '全部', // 类型
        std_nature: '全部', // 标准性质
      },
      option: {
        issue_date: [],
        status: [],
        type: [],
        std_nature: []
      },
    }
  },
  methods: {
    init(agg) {
      // 发布时间
      let issue_date = [{key: '全部'}]
      issue_date = [
        ...issue_date,
        ...agg.issue_date.map(v => {
          return {
            label: moment(v.key).format('YYYY'),
            key: v.key,
            doc_count: v.doc_count
          }
        })
      ]
      this.$set(this.option, 'issue_date', issue_date)
      // 状态
      let status = [{key: '全部'}]
      status = [
        ...status,
        ...agg.status.map(v => {
          return {
            label: v.key,
            key: v.key,
            doc_count: v.doc_count
          }
        })
      ]
      this.$set(this.option, 'status', status)
      // 类型
      this.$set(this.option, 'type', [{key: '全部'}, ...agg.type])
      // 标准性质
      this.$set(this.option, 'std_nature', [{key: '全部'}, ...agg.std_nature])
    },
    handleChangeItem(param, item) {
      this.$set(this.form, param, item.key)
    },
    reset() {
      this.form = {
        issue_date: '全部', // 发布时间
        status: '全部', // 状态
        type: '全部', // 类型
        std_nature: '全部', // 标准性质
      }
    }
  },
  watch: {
    form: {
      handler(newVal, oldVal) {
        this.$emit('getParams', this.form)
      },
      deep: true
    }
  },
  mounted() {
  }
}
</script>

<style lang="scss" scoped>
.tit {
  width: 80px !important;
}
.cont {
  width: calc(100% - 80px) !important;
}
</style>